package com.mall.controller;

import com.mall.entity.CodeNumEntity;
import com.mall.entity.PageBean;
import com.mall.entity.ResponseMessage;
import com.mall.service.RecommendGoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/recommendGood")
public class RecommendGoodController {

    RecommendGoodService recommendGoodService;

    @Autowired
    RecommendGoodController(RecommendGoodService recommendGoodService){
        this.recommendGoodService = recommendGoodService;
    }

    @GetMapping("/{currentPage}/{pageSize}")
    public ResponseMessage getRecommendGoodList(@PathVariable Integer currentPage, @PathVariable Integer pageSize){
        if(currentPage ==null || pageSize ==null){
            return new ResponseMessage(CodeNumEntity.FAIL.getCode(),"未传入数据");
        }
        Map<String, Object> map = new HashMap<>();
        PageBean pageBean = recommendGoodService.getRecommendGoodList(currentPage,pageSize);
        if(pageBean == null){
            return new ResponseMessage(CodeNumEntity.DATABASE_ERROR.getCode(), CodeNumEntity.DATABASE_ERROR.getMessage());
        }
        map.put("message", pageBean);
        return new ResponseMessage(CodeNumEntity.SUCCESS.getCode(), CodeNumEntity.SUCCESS.getMessage(), map);
    }


}
